#ifndef SC_DRAWINGCLASS
#define SC_DRAWINGCLASS
// a class for drawing
#include "points.hpp"
#include "alttree.hpp"
#include <GL/glfw.h>
// EXTRA to max heigh/width, so that springs wouldn't get
// past my screen when moving
#define EXTRA 5
#define WIDTH 640
#define HEIGH 480
#define FRAMERATE 0.040
// aspect ratio modifier (bigger RAT - bigger points)
#define RAT 3.0


// for mouse button presses and keyboard
extern short but;

// just a tinyweeny struct I need for mouse
struct intvec {
    int x;
    int y;
};

struct Cdrawing {
    Cquad tree;         //the quad tree
	float stime;
	float ctime;
	uint frame;
	// -------- data --------
	uint size;
	point* Apoint;
	uint wsize;
	wire* Awire;
	// -------help things ---
	bool* is_act; // points to point being dragged
	vec win_min, win_max, win_asp, win_wh;
	vec win_mouse, win_mouseold;
	float col;       //color variable

	// gets max point koordinates +EXTRA in a vec
	vec maxvec();
	// gets min point koordinates -EXTRA in a vec
	vec minvec();
	// returns x and y aspect ratio in vec
	// needed for nice dot drawing
	vec aspect();

	// screen initialization, returns false if failed
	// vmin and vmax values are a must so far
	bool screen_init(uint width = WIDTH, uint height = HEIGH,
		char name[] = "plop", bool fullscreen = 0);
	void draw_lines();
	void draw_dots();

	// mouse thingies and GUI dot editing
	void mouse_pos();
	bool is_mouse_in(const vec& );
	void dot_drag(point& p);
	void dot_drag2();
	// use 'b' to chase mouse
	void bang();
	// makes current length spring's rest length ('d')
	void deform();
	// reset all point vec values to 0, except for pos and vel
	void reset_point(point &p);

public:
	Cdrawing(point* Apoint = NULL, uint size = 0, wire* Awire = NULL,
	uint wsize = 0);
	~Cdrawing();
	void kill();

	// IF class points are NULL - overwrite, ELSE swap parameters
	void swap_points(point* &P, uint& s);
	// IF class wires are NULL - overwrite, ELSE swap parameters
	void swap_wires(wire* &W, uint& ws);

	// initialization with less parameters, default window mode
	bool init(uint width, uint height, bool f = 0);
	// this is where the drawing happens
	void draw();

	// management..
	void mouse_but();
	bool exit();
	bool time();


	void printp(const point& pt, bool f = 0);
	void printw(bool f = 0);
	void savew();
	void savep();
	void save_on_S();
};

#endif
